﻿#include<stdio.h>
#include<math.h>
#include<GL/glut.h> 
#include<time.h>
#include "bodyShape.h"

// creates the file body.txt if not exists. contains the initial spider arms and juncturas parameters
int BodyFileInit( FILE *b )
{
	int body_array[NUM_OF_DEGREES]={0};
    int i;
	
	b=fopen("Body.txt","w");
	
	for (i=0;i<12;i+=3)
	{
		fprintf(b,"%d %d %d\n",body_array[i],body_array[i+1],body_array[i+2]);
	
	}
	fprintf(b,"%d",body_array[12]);
	fclose(b);
    return 1;
}

//load the parameters from the file body.txt into an array so we can use those parameters
int BodyFileLoad( FILE *b , int body_array_load[] )
{	
	int i;
		
	for (i=0;i<12;i+=3)
	{
		if(fscanf(b,"%d %d %d\n",&body_array_load[i],&body_array_load[i+1],&body_array_load[i+2]) <3)
			exit(1); //break if there's an empty file
	
	}
	fscanf(b,"%d",&body_array_load[12]);
	fclose(b);
    return 1;
}

// saving the spider's body's structure fields in the file body.txt
int BodyFileSave()
{
   int i;
   FILE *b;

   b=fopen("Body.txt","w");
   if (!b) return 0;
    
   for (i=0;i<12;i+=3)
   {
      fprintf(b,"%d %d %d\n",*body_degrees_ptr[i],*body_degrees_ptr[i+1],*body_degrees_ptr[i+2]);

   }
   fprintf(b,"%d",*body_degrees_ptr[12]);

   fclose(b);
   return 1;
}



1); //break if there's an empty file
	
	}
	fscanf(b,"%d",&body_array_load[12]);
	fclose(b);
    return 1;
}

// saving the spider's body's structure fields in the file body.txt
int BodyFileSave()
{
   int i;
   FILE *b;
